const { resolve } = require('path')
const HtmlWebapckPlugin = require('html-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
module.exports = {
  entry: './src/index.js',
  output: {
    filename: './js/app.bundle.js',
    path: resolve(__dirname, '../build'),
    clean: true,
    publicPath: '/',
  },
  mode: 'production',
  plugins: [
    new HtmlWebapckPlugin({
      template: './public/index.html',
    }),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: 'public',
          to: resolve(__dirname, '../build'),
          globOptions: {
            // htmlplug已经处理过index.html了. copyplug不要再处理index.html,否则无法打包
            ignore: ['**/index.html'],
          },
        },
      ],
    }),
  ],
  module: {
    rules: [
      {
        test: /\.ejs$/,
        loader: 'ejs-loader',
        options: {
          variable: 'data',
        },
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
      },
    ],
  },

  resolve: {
    extensions: ['.js', '.json', '.ejs'],
    alias: {
      v: resolve(__dirname, '../src/view'),
    },
  },
}
